package com.ufrn_access;

import java.util.List;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;
import com.maps.CircularItemizedOverlay;



public class CircularActivity extends MapActivity{
	
	int latitude;//UFRN
    int longitude;
    
    boolean useOnlinePosition;
    
    GeoPoint pointUser;

	@Override
	protected boolean isRouteDisplayed() {
		
		return false;
	}
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	    setContentView(R.layout.activity_circular);
	    
	    //obtendo dados de localização

		latitude = (int) (-5.835342 * 1E6);//UFRN
	    longitude = (int) (-35.210924 * 1E6);
	    
	    
	    LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
	    
	    LocationListener locationlistener = new LocationListener(){

			public void onLocationChanged(Location location) {
				CircularActivity.this.latitude = (int) (location.getLatitude() * 1E6);
				CircularActivity.this.longitude = (int) (location.getLongitude() * 1E6);
			}

			public void onProviderDisabled(String arg0) {}

			public void onProviderEnabled(String arg0) {}

			public void onStatusChanged(String arg0, int arg1, Bundle arg2) {}
	    	
	    };
	    try{
	    	locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationlistener);
	    }
	    catch(IllegalArgumentException e){
	    	try{
	    		locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationlistener);
	    	}
	    	catch(IllegalArgumentException iae){
	    		useOnlinePosition = false;
	    	}
	    }
	    
	    //inicializando o mapa
	    MapView mapView = (MapView) findViewById(R.id.mapview);
	    mapView.setBuiltInZoomControls(true);
	    
	    List<Overlay> mapOverlays = mapView.getOverlays();
	    Drawable drawable = this.getResources().getDrawable(R.drawable.alvo);
	    CircularItemizedOverlay itemizedoverlay = new CircularItemizedOverlay(drawable, this);
	    
	    if (!useOnlinePosition){
	    	latitude = -5835342;
	    	longitude = -35210924;
	    }
	    GeoPoint pointUser = new GeoPoint(latitude,longitude);
	    OverlayItem overlayitem = new OverlayItem(pointUser, "Estou aqui (aproximadamente)", null);
	    itemizedoverlay.addOverlay(overlayitem);
	    //seção hardcoded. FECHE OS OLHOS

	    GeoPoint  paradaResidencia_1= new GeoPoint(-5831500,-35204712);
	    OverlayItem overlayitemPs1 = new OverlayItem(paradaResidencia_1, "Residência Universitária", null);
	    itemizedoverlay.addOverlay(overlayitemPs1);
	    
	    GeoPoint  paradaGinasio_2= new GeoPoint(-5834541,-35200635);
	    OverlayItem overlayitemPs2 = new OverlayItem(paradaGinasio_2, "Ginásio Poliesportivo", null);
	    itemizedoverlay.addOverlay(overlayitemPs2);
	    
	    GeoPoint  paradaSetor5_3= new GeoPoint(-5837759,-35196821);
	    OverlayItem overlayitemPs3 = new OverlayItem(paradaSetor5_3, "Setor 5", null);
	    itemizedoverlay.addOverlay(overlayitemPs3);
	    
	    GeoPoint  paradaSetor2_4= new GeoPoint(-5839947,-35195432);
	    OverlayItem overlayitemPs4 = new OverlayItem(paradaSetor2_4, "Setor 2", null);
	    itemizedoverlay.addOverlay(overlayitemPs4);
	    
	    GeoPoint  paradaGeologia_5= new GeoPoint(-5841767,-35195169);
	    OverlayItem overlayitemPs5 = new OverlayItem(paradaGeologia_5, "Dep. de Geologia", null);
	    itemizedoverlay.addOverlay(overlayitemPs5);
	    
	    GeoPoint  paradaNucleoIndustria_6= new GeoPoint(-5843912,-35197143);
	    OverlayItem overlayitemPs6 = new OverlayItem(paradaNucleoIndustria_6, "Núcleo de Tecnologia e Indústria", null);
	    itemizedoverlay.addOverlay(overlayitemPs6);
	    
	    GeoPoint  paradaCeT_7= new GeoPoint(-5843635,-35199900);
	    OverlayItem overlayitemPs7 = new OverlayItem(paradaCeT_7, "Dep. de Ciências e Tecnologia", null);
	    itemizedoverlay.addOverlay(overlayitemPs7);
	    
	    GeoPoint  paradaCB_8= new GeoPoint(-5842157,-35203258);
	    OverlayItem overlayitemPs8 = new OverlayItem(paradaCB_8, "Centro de Biociências", null);
	    itemizedoverlay.addOverlay(overlayitemPs8);
	    
	    GeoPoint  paradaNuplan_9= new GeoPoint(-5840849,-35203950);
	    OverlayItem overlayitemPs9 = new OverlayItem(paradaNuplan_9, "Nuplan", null);
	    itemizedoverlay.addOverlay(overlayitemPs9);
	    
	    GeoPoint  paradaDMP_10= new GeoPoint(-5839067,-35204846);
	    OverlayItem overlayitemPs10 = new OverlayItem(paradaDMP_10, "Div. de material e Patrimônio DMP", "próximo a escola de música");
	    itemizedoverlay.addOverlay(overlayitemPs10);
	    
	    //==============================
	    mapOverlays.add(itemizedoverlay);
	    
	    //
	}
	
}
